package com.itjeffrey.autocode.common;

import com.itjeffrey.autocode.security.JwtUserDetails;
import org.springframework.core.NamedThreadLocal;

/**
 * 系统上下文信息，维护用户登录信息的ThreadLocal变量等
 *
 * @From: Jeffrey
 * @Date: 2020/12/15
 */
public class ACContext {

    private ACContext() {
    }

    private static final ThreadLocal<JwtUserDetails> USER_CONTEXT = new NamedThreadLocal<>("user login info");

    public static void setUserContext(JwtUserDetails jwtUserDetails) {
        USER_CONTEXT.set(jwtUserDetails);
    }

    public static JwtUserDetails getUserContext() {
        return USER_CONTEXT.get();
    }

    public static void removeUserContext() {
        USER_CONTEXT.remove();
    }
}
